﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="diclist.aspx.cs" Inherits="OTA.Notification.Web.Dictionary.diclist" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head id="Head1" runat="server">

    <title>数据字典管理</title>
    <link href="../../Style/main.css" type="text/css" rel="stylesheet" />

    <script src="../../common/jquery-1.2.6.min.js"></script>

    <script src="../../common/jquery-impromptu.1.5.js"></script>

    <script src="../../common/flexigrid/flexigrid.js"></script>

    <link rel="stylesheet" href="../../common/flexigrid/flexigrid.css" type="text/css" media="screen" />
    <link rel="stylesheet" href="../../style/dfbDialog.css" type="text/css" media="screen" />

    <script type="text/javascript" charset="utf-8">
	
	    var dir = new Array();
        var dircode = new Array();
        
		$(document).ready(function(){
		
		    dir.push('Home');
		    dircode.push('');
		    
		    $('#grid').flexigrid({
		        width: $(document).width() - 10,
		        height: 400,
		        //striped:false,
		        
		        url:'?action=get',
		        
		        dataType: 'json',
		        
		        colModel: [
                    {display: 'Id', name : 'id', width : 100, sortable : false, align: 'center'},   
                    {display: 'ParentCode', name : 'ParentCode', width : 180, sortable : false, align: 'left'},   
                    {display: 'Code', name : 'Code', width : 200, sortable : false, align: 'left'},
                    {display: 'Name', name : 'Name', width : 100, sortable : false, align: 'left'},
                    {display: 'Value', name : 'Value', width : 100, sortable : false, align: 'left'},
                    {display: 'Create time', name : 'Create_time', width : 100, sortable : false, align: 'left'} 
                ],
                
                singleSelect: true,
                
                buttons : [
                    { name: '添加', onpress: doCommand},
                    { name: '编辑', onpress: doCommand},
                    { separator: true}   
                ],  
                
                showTableToggleBtn: true,
                rp: 15,
                usepager: true,
                useRp: true,
                query:',' + getLan(), 
                onSuccess: initRow
                
		    });
		    
		    
		    $('#rCN').click(function(){
		        doRefresh();
		    });
		    
		    $('#rEN').click(function(){
		    
		        doRefresh();
		        	        
		    });
		    
		});
		
	    function initRow() 
        {
            $('#grid tbody tr td').each(function() {
            
                $(this).dblclick(function(e) {
                
                    var row = $(this).parents('tr');
                    
                    var id = row.children('td').eq(0).children('div').text();
                    var code = row.children('td').eq(2).children('div').text();
                    
                    var url = 'directory.aspx?id=' + id + '&code=';
                    
                    for(var i in dircode){
                        if(dircode[i] != ''){
                            url += '|' + dircode[i];
                        }
                    }
                    
                    if(code != ' ')
                        url += '|' + code;

                    ShowBox(url, 450);
                    
                });
            });
            
		    $('#grid a').click(function(){
		    
                var row = $(this).parents('tr');
                
                var code = row.children('td').eq(2).children('div').text();
                var name = row.children('td').eq(3).children('div').text();
                
                
                enterCode(code, name);
                
		        return false;
		    });
            
        }
		
		function getLan(){
		
		    var lan = 'zh-cn';
		    
		    if($('#rCN').attr('checked')){
		        return lan;
		    }
		    else
		        return 'en-us';
		
		}
		
		function enterCode(code, name){
		
		     if(code == "id__home__[A]"){
		        code = "";
		        name = "Home";
		     }

		     var p = -1;
		     
		     for(var i in dircode){
		        
		        if(dircode[i] == code){
		            //code found! back to code.
		            p = i;
		            break;
		        }
		     }
		     
		     
		     
		     //rebuild array, copy array
		     
		     if(p >= 0){
		     
		         var newdir = new Array();
		         var newdirCode = new Array();
    		
		         for(var i in dircode){
    		     
		            if(i <= p){
    		            newdir.push(dir[i]);
    		            newdirCode.push(dircode[i]);
		            }
		            else break;
		         }
		         
		         dir = newdir;
		         dircode = newdirCode;
		     }
		     else{
		         dir.push(name);
		         dircode.push(code);
		         
		     }
		     
             var params = "";
             
             params = code + ',' + getLan();

		     $('#grid').flexOptions({
		     
		        page: 0, 
		        query: params
		        
		     }).flexReload();
		     
		     

		     rebuildNav();
		     
		}
		
		
		function doCommand(com, grid){
		
            if (com=='编辑'){
            
                if($('.trSelected', grid)[0] == null) return;

                var id = $('.trSelected', grid)[0].id.replace(/row/,"");
                var code = $('.trSelected', grid)[0].cells[2].innerText;
                
                var url = 'directory.aspx?id=' + id + '&code=';
                    
                for(var i in dircode){
                     if(dircode[i] != ''){
                        url += '|' + dircode[i];
                     }
                }
                
                if(code != ' ') url += '|' + code;

                ShowBox(url, 450);
                    
            }
            else if(com == '添加'){
            
                var code = dircode[dircode.length - 1];
                
                ShowBox('directory.aspx?code=' + code, 450);
            }
        }
        
        
        function doRefresh(){
        
             var code = dircode[dircode.length - 1];
        
             var params = "";
             
             params = code + ',' + getLan();

		     $('#grid').flexOptions({
		     
		        page: 0, 
		        query: params
		        
		     }).flexReload();
        }
        
        //dialog
        
        function ShowBox(url, height){
    
            $.prompt("<iframe src=\"" + url + "\" width=\"100%\" frameborder=\"0\" height=\"" + height + "\"></iframe>");
            
            $('div .jqi button').hide();
        }
        
        function Close(){
        
            $('div .jqi button').click();
            
            doRefresh();
        }
        
        
        //nav
        
        function rebuildNav(){
        
            var html = "";
            var index = 0;
            
            $.each(dir, function(i, item){
            
                if (dircode[i] == "")
                    html += "<a href=\"#\" id=\"id__home__[A]\">" + item + "</a>";
                else {

                    if(i + 1 >= dir.length){
                        html += " > " + item;
                    }
                    else
                        html += " > " + "<a href=\"#\" id=\"" + dircode[i] + "\">" + item + "</a>";
                }            
                
            });

            $('#nav').html(html);
            
            $('#nav a').click(function(){
            
                var code = $(this).attr("id");
                var name = $(this).text();
                
                enterCode(code, name);
                
                return false;
            });
        }
        
    </script>

</head>
<body>
    <form id="form1" runat="server"></form>
    <div>
        <span id="nav"></span>&nbsp;
        语言:
        <input id="rCN" type="radio" name="rlan" />中文 <input id="rEN" type="radio" name="rlan" checked /> English
        <table id="grid">
        </table>
        
    </div>
    
</body>
</html>

